package lumis.service.doui.filters;

import java.util.Iterator;

import org.w3c.dom.Node;

import lumis.doui.source.ISourceData;
import lumis.doui.source.Source;
import lumis.doui.source.TabularData;
import lumis.doui.source.postloadprocessor.IPostLoadProcessor;
import lumis.portal.PortalException;
import lumis.portal.authentication.SessionConfig;
import lumis.util.ITransaction;

/**
 * Remove from a TabularData populated with source fields all fields that cannot be filtered 
 *
 * @version $Revision: 6376 $ $Date: 2007-04-10 17:55:53 -0300 (Tue, 10 Apr 2007) $
 * @since 4.0.10
 */
public class FilterableFieldsPostLoadProcessor implements IPostLoadProcessor
{
	public void processSource(SessionConfig sessionConfig, Source source, Node parametersNode, ITransaction transaction) throws PortalException
	{
		TabularData tabularData = (TabularData)source.getData();
		for(Iterator<ISourceData> iterator = tabularData.getRows().iterator(); iterator.hasNext();)
		{
			ISourceData row = iterator.next();
			String dataType = row.get("dataType", String.class);
			if ("image".equals(dataType) || "document".equals(dataType) || "file".equals(dataType) || "files".equals(dataType))
				iterator.remove();
		}
	}
}
